package com.dragon.repository.domain.dto;

import com.dragon.common.util.BeanUtils;
import com.dragon.repository.entity.Stock;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * @author sy
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class StockDTO {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "主id")
    private Integer id;

    @ApiModelProperty(value = "仓库id")
    private Integer warehouseId;

    @ApiModelProperty(value = "产品sku_id")
    private Integer productSkuId;

    @ApiModelProperty(value = "计量单位id")
    private Integer unitId;

    @ApiModelProperty(value = "原有数量")
    private Double quantity;

//    @ApiModelProperty(value = "剩下的数量")
//    private Double leftoverNum;

    @ApiModelProperty(value = "公司id")
    private Integer companyId;

    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    @ApiModelProperty(value = "修改时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;

    @ApiModelProperty(value = "仓库名称")
    private String warehouseName;

    @ApiModelProperty(value = "规格名称")
    private String specificationName;

    @ApiModelProperty(value = "产品名称")
    private String productName;

    @ApiModelProperty(value = "单位名称")
    private String unitName;

    @ApiModelProperty(value = "类别名称")
    private String categoryName;

    @ApiModelProperty(value = "类别id")
    private Integer categoryId;


    public StockDTO() {}

    public StockDTO(Stock entity) {
        BeanUtils.copyProperties(entity,this);
    }

    public static StockDTO convert(Stock entity) {
        return new StockDTO(entity);
    }

    public static List<StockDTO> convertList(List<Stock> list) {
        List<StockDTO> resultList = new ArrayList<>();
        for (Stock entity : list) {
            resultList.add(new StockDTO(entity));
        }
        return resultList;
    }}
